/*******************************************************************************
 * Copyright 2009-2020 Amazon Services. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 *
 * You may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 * specific language governing permissions and limitations under the License.
 *******************************************************************************
 * Marketplace Web Service Orders
 * API Version: 2013-09-01
 * Library Version: 2020-02-03
 * Generated: Fri Feb 28 01:33:29 UTC 2020
 */
package com.yunchang.springboot.scheduled.MWS.ordersSample;

import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.*;
import javax.xml.datatype.XMLGregorianCalendar;
import java.math.BigDecimal;

import com.amazonservices.mws.client.*;
import com.amazonservices.mws.orders._2013_09_01.*;
import com.amazonservices.mws.orders._2013_09_01.model.*;
import com.amazonservices.mws.orders._2013_09_01.samples.MarketplaceWebServiceOrdersSampleConfig;
import com.yunchang.springboot.config.MWS.MarketplaceWebServiceOrdersConfig;

/** Sample async call for ListOrders. */
public class ListOrdersAsyncSample {

    /**
     * Call the service, log response and exceptions.
     *
     * @param client
     * @param requestList
     *
     * @return The response.
     */
    public static List<Object> invokeListOrders(MarketplaceWebServiceOrdersAsync client, List<ListOrdersRequest> requestList) throws ExecutionException, InterruptedException {
        // Call the service async.
        List<Future<ListOrdersResponse>> futureList = 
            new ArrayList<Future<ListOrdersResponse>>();
        for (ListOrdersRequest request : requestList) {
            Future<ListOrdersResponse> future = client.listOrdersAsync(request);
            ListOrdersResponse response = future.get();
//            ResponseHeaderMetadata rhmd = response.getResponseHeaderMetadata();
            System.out.println("-------------------------------------------------------------------------------------------------------------");
            System.out.println("sellerId:" + request.getSellerId());
            System.out.println("-------------------------------------------------------------------------------------------------------------");
            //String responseXml = response.toXML();
            //futureList.add(future);
        }
        List<Object> responseList = new ArrayList<Object>();
//        for (Future<ListOrdersResponse> future : futureList) {
//            Object xresponse;
//            try {
//                ListOrdersResponse response = future.get();
//                ResponseHeaderMetadata rhmd = response.getResponseHeaderMetadata();
//                // We recommend logging every the request id and timestamp of every call.
//                System.out.println("Response:");
//                System.out.println("RequestId: "+rhmd.getRequestId());
//                System.out.println("Timestamp: "+rhmd.getTimestamp());
//                //System.out.println(responseXml);
//                xresponse = response;
//            } catch (ExecutionException ee) {
//                Throwable cause = ee.getCause();
//                if (cause instanceof MarketplaceWebServiceOrdersException) {
//                    // Exception properties are important for diagnostics.
//                    MarketplaceWebServiceOrdersException ex =
//                        (MarketplaceWebServiceOrdersException)cause;
//                    ResponseHeaderMetadata rhmd = ex.getResponseHeaderMetadata();
//                    System.out.println("Service Exception:");
//                    System.out.println("RequestId: "+rhmd.getRequestId());
//                    System.out.println("Timestamp: "+rhmd.getTimestamp());
//                    System.out.println("Message: "+ex.getMessage());
//                    System.out.println("StatusCode: "+ex.getStatusCode());
//                    System.out.println("ErrorCode: "+ex.getErrorCode());
//                    System.out.println("ErrorType: "+ex.getErrorType());
//                    xresponse = ex;
//                } else {
//                    xresponse = cause;
//                }
//            } catch (Exception e) {
//                xresponse = e;
//            }
//            responseList.add(xresponse);
//        }
        return responseList;
    }

    /**
     *  Command line entry point.
     */
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        // Get a client connection.
        //MarketplaceWebServiceOrdersAsyncClient client = MarketplaceWebServiceOrdersConfig.getAsyncClient();

        // Create a request list.
        List<ListOrdersRequest> requestList = new ArrayList<ListOrdersRequest>();
        ListOrdersRequest request = new ListOrdersRequest();
        String sellerId = "AR7H1RL9GCUCS";
        request.setSellerId(sellerId);
        String mwsAuthToken = "amzn.mws.22b2d982-5455-379c-de2c-4c73530136c9";
        request.setMWSAuthToken(mwsAuthToken);
        XMLGregorianCalendar createdAfter = MwsUtl.getDTF().newXMLGregorianCalendar();
        createdAfter.setYear(2020);
        createdAfter.setMonth(5);
        createdAfter.setDay(5);
        createdAfter.setTime(12,0,0);
        System.out.println(createdAfter.toString());
        request.setCreatedAfter(createdAfter);
//        XMLGregorianCalendar createdBefore = MwsUtl.getDTF().newXMLGregorianCalendar();
//        request.setCreatedBefore(createdBefore);
//        XMLGregorianCalendar lastUpdatedAfter = MwsUtl.getDTF().newXMLGregorianCalendar();
//        request.setLastUpdatedAfter(lastUpdatedAfter);
//        XMLGregorianCalendar lastUpdatedBefore = MwsUtl.getDTF().newXMLGregorianCalendar();
//        request.setLastUpdatedBefore(lastUpdatedBefore);
        List<String> orderStatus = new ArrayList<String>();
        request.setOrderStatus(orderStatus);
        List<String> marketplaceId = new ArrayList<String>();
        marketplaceId.add("ATVPDKIKX0DER");
        marketplaceId.add("A2EUQ1WTGCTBG2");
        request.setMarketplaceId(marketplaceId);
        List<String> fulfillmentChannel = new ArrayList<String>();
        request.setFulfillmentChannel(fulfillmentChannel);
        List<String> paymentMethod = new ArrayList<String>();
        request.setPaymentMethod(paymentMethod);
        String buyerEmail = null;
        request.setBuyerEmail(buyerEmail);
        String sellerOrderId = null;
        request.setSellerOrderId(sellerOrderId);
        Integer maxResultsPerPage = 3;
        request.setMaxResultsPerPage(maxResultsPerPage);
        List<String> tfmShipmentStatus = new ArrayList<String>();
        request.setTFMShipmentStatus(tfmShipmentStatus);
        List<String> easyShipShipmentStatus = new ArrayList<String>();
        request.setEasyShipShipmentStatus(easyShipShipmentStatus);
        requestList.add(request);

        ListOrdersRequest request1 = new ListOrdersRequest();
        String sellerId1 = "A125R95P2RN68Z";
        request1.setSellerId(sellerId1);
        String mwsAuthToken1 = "amzn.mws.b8b76aa1-5fd4-4423-c5d2-565b0537fa4e";
        request1.setMWSAuthToken(mwsAuthToken1);
        XMLGregorianCalendar createdAfter1 = MwsUtl.getDTF().newXMLGregorianCalendar();
        createdAfter1.setYear(2020);
        createdAfter1.setMonth(5);
        createdAfter1.setDay(5);
        createdAfter1.setTime(12,0,0);
        request1.setCreatedAfter(createdAfter1);
//        XMLGregorianCalendar createdBefore = MwsUtl.getDTF().newXMLGregorianCalendar();
//        request.setCreatedBefore(createdBefore);
//        XMLGregorianCalendar lastUpdatedAfter = MwsUtl.getDTF().newXMLGregorianCalendar();
//        request.setLastUpdatedAfter(lastUpdatedAfter);
//        XMLGregorianCalendar lastUpdatedBefore = MwsUtl.getDTF().newXMLGregorianCalendar();
//        request.setLastUpdatedBefore(lastUpdatedBefore);
        List<String> orderStatus1 = new ArrayList<String>();
        request1.setOrderStatus(orderStatus1);
        List<String> marketplaceId1 = new ArrayList<String>();
        marketplaceId1.add("ATVPDKIKX0DER");
        request1.setMarketplaceId(marketplaceId1);
        List<String> fulfillmentChannel1 = new ArrayList<String>();
        request1.setFulfillmentChannel(fulfillmentChannel1);
        List<String> paymentMethod1 = new ArrayList<String>();
        request1.setPaymentMethod(paymentMethod1);
        String buyerEmail1 = null;
        request1.setBuyerEmail(buyerEmail1);
        String sellerOrderId1 = null;
        request1.setSellerOrderId(sellerOrderId1);
        Integer maxResultsPerPage1 = 3;
        request1.setMaxResultsPerPage(maxResultsPerPage1);
        List<String> tfmShipmentStatus1 = new ArrayList<String>();
        request.setTFMShipmentStatus(tfmShipmentStatus1);
        List<String> easyShipShipmentStatus1 = new ArrayList<String>();
        request1.setEasyShipShipmentStatus(easyShipShipmentStatus1);
        requestList.add(request1);

        // Make the calls.
        //ListOrdersAsyncSample.invokeListOrders(client, requestList);
    }

}
